package com.caigou.comm.base.network.interceptors

import okhttp3.Interceptor
import okhttp3.Response
import java.util.*

/**
 * @author #Suyghur.
 * Created on 2021/09/13
 */
class HeadersInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val builder = request.newBuilder()

//        builder.addHeader("Content-type", "application/json;charset=utf-8")
//            .header("model", "Android")
//            .header("If-Modified-Since", "${Date()}")
//            .header("User-Agent", System.getProperty("http.agent") ?: "unknown")
        builder.header("model", "Android")
            .header("If-Modified-Since", "${Date()}")
            .header("User-Agent", System.getProperty("http.agent") ?: "unknown")

//        val domain = request.url.host
//        val url = request.url.toString()
//        if (domain.isNotEmpty()) {
//            val spDomain = Prefs.getString(domain, "")
//            val cookie = if (spDomain.isNotEmpty()) {
//                spDomain
//            } else {
//                ""
//            }
//            if (cookie.isNotEmpty()) {
//                // 将Cookie添加到请求头
//                builder.addHeader(HttpConstant.COOKIE_NAME, cookie)
//            }
//        }

        return chain.proceed(builder.build())
    }
}